#!/bin/bash

# 输出调试信息
echo "Current URL_PATH value: $URL_PATH"

# 如果URL_PATH为空或未定义，则设置默认值
if [ -z "$URL_PATH" ]; then
    echo "URL_PATH is not set, using default value: mobile"
    export URL_PATH="mobile"
else
    echo "Using provided URL_PATH value: $URL_PATH"
fi

# 设置API_URL（保持原有逻辑）
export API_URL="${API_URL:-http://hrsmapi.beraising.cn/}"

# 输出最终使用的值
echo "Final URL_PATH value: $URL_PATH"
echo "Final API_URL value: $API_URL"

# 替换 Nginx 配置中的变量
envsubst '$API_URL $URL_PATH' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf

# 验证配置文件替换结果
echo "Generated Nginx configuration:"
cat /etc/nginx/conf.d/default.conf

# 启动 Nginx
exec nginx -g 'daemon off;'